﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BKH.BLL;


namespace BKH.MyUserControl.UCHienThi
{
    public partial class ucThemNguoiNha : UserControl
    {
        int idBN;
        public ucThemNguoiNha(int id)
        {
            InitializeComponent();
            this.idBN = id;
            showCbbRelationship();
            showInfoBN();
        }

        void showInfoBN()
        {
            BenhNhanBUO bn = new BenhNhanBUO();
            tbl_BenhNhan obj = new tbl_BenhNhan();
            obj=bn.GetSingle(idBN);
            lblBenhNhan.Text = obj.FirstName + " " + obj.LastName;
            lblBHYT.Text = obj.BHYT;
            lblCMND.Text = obj.CMND;
        }
        /// <summary>
        /// Hiển thị thông tin quan hệ với bệnh nhân lên combobox
        /// </summary>
        void showCbbRelationship()
        {
            RelationshipBUO r = new RelationshipBUO();
            cbbRelationship.DataSource = r.GetAll();
            cbbRelationship.DisplayMember = "RelationShipName";
            cbbRelationship.ValueMember = "RelationShipID";
        }
        /// <summary>
        /// Thêm thông tin người nhà
        /// </summary>
        void insertThongTinNguoiNha()
        {
            NguoiNhaBUO nguoiNha = new NguoiNhaBUO();
            tbl_ThanNhan obj = new tbl_ThanNhan();
            obj.BenhNhanID = idBN;
            obj.FirstName=txtFirstName.Text;
            obj.LastName=txtLastName.Text;
            obj.RelationShipID = int.Parse(cbbRelationship.SelectedValue.ToString());
            obj.Tel = txtTel.Text;
            obj.Address = txtAddress.Text;
            if (nguoiNha.Insert(obj)==true)
            {
                lblThongBao.Text = "Thêm thông tin người nhà thành công";
            }
            else
            {
                lblThongBao.Text = "Thêm thông tin người nhà KO thành công";
            }
            
        }

        private void btnThemNguoiNha_Click(object sender, EventArgs e)
        {
            insertThongTinNguoiNha();
        }

        private void radioButtonThem_CheckedChanged(object sender, EventArgs e)
        {
            btnThemNguoiNha.Enabled = true;
            btnSua.Enabled = false;
            btnXoa.Enabled = false;
        }

        private void radioButtonSua_CheckedChanged(object sender, EventArgs e)
        {
            btnThemNguoiNha.Enabled = false;
            btnSua.Enabled = true;
            btnXoa.Enabled = false;
        }

        private void radioButtonXoa_CheckedChanged(object sender, EventArgs e)
        {
            btnThemNguoiNha.Enabled = false;
            btnSua.Enabled = false;
            btnXoa.Enabled = true;
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            tbl_ThanNhan obj = new tbl_ThanNhan();
            NguoiNhaBUO ngNha = new NguoiNhaBUO();
            obj.FirstName = txtFirstName.Text;
            obj.LastName = txtLastName.Text;
            obj.RelationShipID=int.Parse(cbbRelationship.SelectedValue.ToString());
            obj.Tel = txtTel.Text;
            obj.Address = txtAddress.Text;
            if (ngNha.Update(idBN,obj)==true)
            {
                lblThongBao.Text = "Sửa thành công";
            }
            else
            {
                lblThongBao.Text = "Sửa ko thành công";
            }
        }
    }
}
